﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdverseEventReportSystem.Utils {
    /// <summary>
    /// Log4net日志处理基类
    /// </summary>
    public class Log4netBase : ILog {
        /// <summary>
        /// 返回Log实例
        /// </summary>
        private readonly log4net.ILog log;

        #region 构造初始化
        /// <summary>
        /// 初始化日志处理相关配置
        /// </summary>
        /// <param name="loggerName">日志实例名</param>
        /// <param name="isWatchFile">是否监控配置文件变化</param>
        public Log4netBase(string loggerName, bool isWatchFile = false) {
            //初始化log4net配置
            Log4netConfig.SetConfig(loggerName, isWatchFile);

            //获取Logger
            this.log = log4net.LogManager.GetLogger(loggerName);
        }
        #endregion

        #region 记录Log
        /// <summary>
        /// Toes the error.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        public void ToError(object msg) {
            this.log.Error(msg);
        }

        /// <summary>
        /// Toes the error.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="ex">The ex.</param>
        public void ToError(object msg, Exception ex) {
            this.log.Error(msg, ex);
        }

        /// <summary>
        /// Toes the debug.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        public void ToDebug(object msg) {
            this.log.Debug(msg);
        }

        /// <summary>
        /// Toes the debug.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="ex">The ex.</param>
        public void ToDebug(object msg, Exception ex) {
            this.log.Debug(msg, ex);
        }

        /// <summary>
        /// Toes the fatal.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        public void ToFatal(object msg) {
            this.log.Fatal(msg);
        }

        /// <summary>
        /// Toes the fatal.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="ex">The ex.</param>
        public void ToFatal(object msg, Exception ex) {
            this.log.Fatal(msg, ex);
        }

        /// <summary>
        /// Toes the info.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        public void ToInfo(object msg) {
            this.log.Info(msg);
        }

        /// <summary>
        /// Toes the info.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="ex">The ex.</param>
        public void ToInfo(object msg, Exception ex) {
            this.log.Info(msg, ex);
        }

        /// <summary>
        /// Toes the warn.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        public void ToWarn(object msg) {
            this.log.Warn(msg);
        }

        /// <summary>
        /// Toes the warn.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="ex">The ex.</param>
        public void ToWarn(object msg, Exception ex) {
            this.log.Warn(msg, ex);
        }
        #endregion

        #region 属性
        /// <summary>
        /// Gets the logger.
        /// </summary>
        /// <value>The logger.</value>
        public log4net.Core.ILogger Logger {
            get {
                return this.log.Logger;
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is debug enabled.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is debug enabled; otherwise, <c>false</c>.
        /// </value>
        public bool IsDebugEnabled {
            get {
                return this.log.IsDebugEnabled;
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is error enabled.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is error enabled; otherwise, <c>false</c>.
        /// </value>
        public bool IsErrorEnabled {
            get {
                return this.log.IsErrorEnabled;
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is fatal enabled.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is fatal enabled; otherwise, <c>false</c>.
        /// </value>
        public bool IsFatalEnabled {
            get {
                return this.log.IsFatalEnabled;
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is info enabled.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is info enabled; otherwise, <c>false</c>.
        /// </value>
        public bool IsInfoEnabled {
            get {
                return this.log.IsInfoEnabled;
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is warn enabled.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is warn enabled; otherwise, <c>false</c>.
        /// </value>
        public bool IsWarnEnabled {
            get {
                return this.log.IsWarnEnabled;
            }
        }
        #endregion
    }
}
